package com.example.springtest.Service;

import com.example.springtest.Dao.DaoImp;
import com.example.springtest.user;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
@Component
public class ServiceImp  implements Service{
    @Autowired
    DaoImp dao;
    @Override
    public List<user> findAll() throws FileNotFoundException {
        ArrayList<String> list=dao.findAll();
        List<user> result=list.stream().map((line)->{
            String[] str=line.split(",");
            Integer id=Integer.parseInt(str[0]);
            String username=str[1];
            String password=str[2];
            String name=str[3];
            Integer age=Integer.parseInt(str[4]);
            String updateTime=str[5];
            return new user(id,username,password,name,age,updateTime);
        }).toList();
        return result;
    }
}
